from time import sleep
from Model.user.User import *
from Model.default import Base,engine
from Model.community.common_text import *
from Model.mysocketio.info import *
from Model.notice_message.main import  *
Base.metadata.create_all(engine)
sleep(2)
from sqlalchemy.orm import sessionmaker
from  sqlalchemy import text
session=sessionmaker(bind=engine)()

def init_staticdata():
    try:
        static=static_data(id=1)
        session.add(static)
        session.commit()
        pass
    except Exception as e:
        # print(e)
        session.rollback()
        session.close()

# 如果如果有，存在的表，他不会创建。因为该段只是创建，如果你需要添加字段可以使用原生sql
def updata_new_Column(TABLE,COLUMN,TYPE,LIMIT):
    session=sessionmaker(bind=engine)()
    try:
        update_stmt=text(f'ALTER TABLE {TABLE} ADD {COLUMN} {TYPE} {LIMIT}')
        session.execute(update_stmt)
        session.commit()
    except Exception as e:

        session.rollback()
        session.close()




